<template>
  <div>
    <el-table
      ref="table"
      v-loading="crud.loading"
      border
      :data="crud.data"
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
      row-key="id"
      max-height="350"
      @select="crud.selectChange"
      @select-all="crud.selectAllChange"
      @selection-change="crud.selectionChangeHandler"
    >
      <el-table-column :show-overflow-tooltip="true" label="脚本名称" prop="fileName" min-width="180" />
      <el-table-column :show-overflow-tooltip="true" label="操作人" prop="crtUserName" min-width="100" />
      <el-table-column :show-overflow-tooltip="true" label="操作时间" prop="crtTs" min-width="150" />
      <el-table-column :show-overflow-tooltip="true" label="预览" prop="isEdit" min-width="100">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="showFileContent(scope.row.pkId)">预览</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <div style="line-height: 20px; height: 20px;">
      <pagination />
    </div>

    <!-- 同屏对比 -->
    <el-dialog :visible.sync="isShowComparison" append-to-body title="脚本同屏对比" width="90%" top="5vh">
      <same-screen-comparison v-if="isShowComparison" :opt-history-pk-id="optHistoryPkId" />
    </el-dialog>
  </div>
</template>
<script>
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import pagination from '@crud/Pagination'
import sameScreenComparison from './same-screen-comparison'
import scriptConvertListApi from '@/api/script/transfer/script-convert-list'

const defaultCrud = CRUD({ title: '操作历史', url: 'api/script/convert/list/his', crudMethod: { ...scriptConvertListApi }})
const defaultForm = {}

export default {
  name: 'ScriptDetail',
  components: { pagination, sameScreenComparison },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  props: {
    convertListPkId: {
      required: true,
      type: String
    }
  },
  data() {
    return {
      isShowComparison: false,
      optHistoryPkId: null
    }
  },
  created() {
  },
  methods: {
    [CRUD.HOOK.beforeRefresh](crud) {
      crud.query.scriptConvertListId = this.convertListPkId
    },
    showFileContent(pkId) {
      this.isShowComparison = true
      this.optHistoryPkId = pkId
    }
  }
}
</script>

